<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登入 - RoubSiteAdmin</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<script src="{$__WEBPATH__}/static/common/js/roubSite.js"></script>
<script type="text/javascript">
	RS.webPath = '{$__WEBPATH__}';
</script>
<script type="text/javascript">
	var retUrl = '{$reUrl}';
	if (retUrl == '') {
		retUrl = RS.webPath + "/admin";
	}
</script>
<link rel="stylesheet" href="{$__WEBPATH__}/static/common/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="{$__WEBPATH__}/static/admin/css/admin.css" media="all">
<link rel="stylesheet" href="{$__WEBPATH__}/static/admin/login/css/login.css" media="all">
</head>
<body>

	<div class="layadmin-user-login layadmin-user-display-show" id="RoubSite-user-login" style="display: none;">
		<div class="layadmin-user-login-main">
			<div class="layadmin-user-login-box layadmin-user-login-header">
				<h2>RoubSiteAdmin</h2>
				<p>快速开发框架</p>
			</div>
			<div class="layadmin-user-login-box layadmin-user-login-body">
				<form action="" class="layui-form">
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="username"></label> <input type="text" name="username" id="username" lay-verify="required" placeholder="用户名" class="layui-input">
					</div>
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="pwd"></label> <input type="password" name="pwd" id="pwd" lay-verify="required" placeholder="密码" class="layui-input">
					</div>
					<div class="layui-form-item">
						<div class="layui-row">
							<div class="layui-col-xs7">
								<label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="verifyImg"></label> <input type="text" name="verifyImg" id="verifyImg" lay-verify="required" placeholder="图形验证码" class="layui-input">
							</div>
							<div class="layui-col-xs5">
								<div style="margin-left: 10px;">
									<img src="{$__WEBPATH__}/admin/verifyCode" class="layadmin-user-login-codeimg" id="verifyImg_img">
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="RoubSite-submit">登 入</button>
					</div>
				</form>
			</div>
		</div>
	</div>

	<div class="layui-trans layadmin-user-login-footer">

		<p>
			© 2020 <a href="http://www.roubsite.com/" target="_blank">RoubSite.com</a>
		</p>
	</div>


	<script src="{$__WEBPATH__}/static/common/layuiadmin/layui/layui.js"></script>
	<script>
		function Base64() {
			// private property 
			_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
			// public method for encoding 
			this.encode = function(input) {
				var output = "";
				var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
				var i = 0;
				input = _utf8_encode(input);
				while (i < input.length) {
					chr1 = input.charCodeAt(i++);
					chr2 = input.charCodeAt(i++);
					chr3 = input.charCodeAt(i++);
					enc1 = chr1 >> 2;
					enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
					enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
					enc4 = chr3 & 63;
					if (isNaN(chr2)) {
						enc3 = enc4 = 64;
					} else if (isNaN(chr3)) {
						enc4 = 64;
					}
					output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2)
							+ _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
				}
				return output;
			}
			// public method for decoding 
			this.decode = function(input) {
				var output = "";
				var chr1, chr2, chr3;
				var enc1, enc2, enc3, enc4;
				var i = 0;
				input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
				while (i < input.length) {
					enc1 = _keyStr.indexOf(input.charAt(i++));
					enc2 = _keyStr.indexOf(input.charAt(i++));
					enc3 = _keyStr.indexOf(input.charAt(i++));
					enc4 = _keyStr.indexOf(input.charAt(i++));
					chr1 = (enc1 << 2) | (enc2 >> 4);
					chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
					chr3 = ((enc3 & 3) << 6) | enc4;
					output = output + String.fromCharCode(chr1);
					if (enc3 != 64) {
						output = output + String.fromCharCode(chr2);
					}
					if (enc4 != 64) {
						output = output + String.fromCharCode(chr3);
					}
				}
				output = _utf8_decode(output);
				return output;
			}
			// private method for UTF-8 encoding 
			_utf8_encode = function(string) {
				string = string.replace(/\r\n/g, "\n");
				var utftext = "";
				for (var n = 0; n < string.length; n++) {
					var c = string.charCodeAt(n);
					if (c < 128) {
						utftext += String.fromCharCode(c);
					} else if ((c > 127) && (c < 2048)) {
						utftext += String.fromCharCode((c >> 6) | 192);
						utftext += String.fromCharCode((c & 63) | 128);
					} else {
						utftext += String.fromCharCode((c >> 12) | 224);
						utftext += String.fromCharCode(((c >> 6) & 63) | 128);
						utftext += String.fromCharCode((c & 63) | 128);
					}
				}
				return utftext;
			}
			// private method for UTF-8 decoding 
			_utf8_decode = function(utftext) {
				var string = "";
				var i = 0;
				var c = c1 = c2 = 0;
				while (i < utftext.length) {
					c = utftext.charCodeAt(i);
					if (c < 128) {
						string += String.fromCharCode(c);
						i++;
					} else if ((c > 191) && (c < 224)) {
						c2 = utftext.charCodeAt(i + 1);
						string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
						i += 2;
					} else {
						c2 = utftext.charCodeAt(i + 1);
						c3 = utftext.charCodeAt(i + 2);
						string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6)
								| (c3 & 63));
						i += 3;
					}
				}
				return string;
			}
		}

		layui.use([ 'layer', 'form' ], function() {
			layer = layui.layer;
			$ = layui.$;
			var form = layui.form;
			$("body").on("click", "#verifyImg_img", function() {
				refCOde();
			});

			function refCOde() {
				$('#verifyImg_img').attr('src',
						RS.webPath + "/admin/verifyCode?t=" + new Date().getTime());
			}
			form.render();
			form.on('submit(RoubSite-submit)', function(data) {
				console.log(data.field);
				var username = $('#username').val();
				var pwd = $('#pwd').val();
				var base = new Base64();
				pwd = base.encode(pwd);
				var verifyImg = $('#verifyImg').val();
				$.ajax({
						url : '{$__WEBPATH__}/admin/login/login',
						data : 'username=' + username + '&pwd=' + encodeURIComponent(pwd)
								+ '&verifyImg=' + verifyImg,
						type : "post",
						dataType : "json",
						success : function(data) {
							switch (String(data.status)) {
							case '-1':
								layer.msg("该用户不存在!");
								refCOde();
								break;
							case '-2':
								layer.msg("密码错误!");
								refCOde();
								break;
							case '-3':
								layer.msg("验证码错误!");
								refCOde();
								break;
							case '1':
								layer.msg("登陆成功");
								window.location.href = retUrl;
								break;
							case '-4':
								layer.msg("用户已注销");
								refCOde();
								break;
							case '-5':
								layer.msg("用户被锁定请于" + data.expTime + "之后再尝试");
								refCOde();
								break;
							case '-10':
								layer.msg("验证码超时!");
								refCOde();
								break;
							default:
								break;
							}
						}
				});
				return false;
			});
		});
	</script>
</body>
</html>